package com.leyou.common.exception.handler;

import com.leyou.common.exception.pojo.ExceptionResult;
import com.leyou.common.exception.pojo.LyException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 *  @ControllerAdvice 表示要对所有处理器进行增强
 */
@ControllerAdvice
public class ControllerExceptionHandler {

    /**
     * 编写一个处理LyException异常的处理器，此处理器会在发现LyException异常时自动触发
     */
    @ExceptionHandler(LyException.class)
    public ResponseEntity<ExceptionResult> handlerLyException(LyException e){
        return ResponseEntity.status(e.getStatus()).body(new ExceptionResult(e));
    }

}
